﻿using System;
using System.Collections.Generic;
using NUnit.Framework;

namespace FazaDemo.BL.Services_
{
    
    [TestFixture]
    public class InfoListsProviderTests : EcqTextParserTestsBase
    {
      
        private InfoListsProvider _provider;

        [SetUp]
        public void TestInit()
        {
            _provider = new InfoListsProvider();
        }

        [Test]
        [TestCaseSource("GetEcqFields")]
        public string GetInfoLists_VarEcqs_ReturnStartIndex(string ecqText)
        {
            try
            {
                //Act
                IList<List<string>> resultLists = _provider.GetInfoLists(ecqText);
                ////Assert
                return resultLists[0][0];
            }
            catch (Exception)
            {
                return null;
            }
        }

        [Test]
        [TestCaseSource("GetEcqFieldsRandomIndexes")]
        public string GetInfoLists_VarEcqs_ReturnRandomIndex(string ecqText)
        {
            try
            {
                IList<List<string>> resultLists = _provider.GetInfoLists(ecqText);
                return resultLists[1][2];
            }
            catch (Exception)
            {
                return null;
            }
        }

        [Test]
        [TestCaseSource("GetEcqFieldsLatestIndexes")]
        public string GetInfoLists_VarEcqs_ReturnLatestIndex(string ecqText)
        {
            try
            {
                IList<List<string>> resultLists = _provider.GetInfoLists(ecqText);
                var latestIndex = resultLists.Count - 1;
                return resultLists[latestIndex][resultLists[latestIndex].Count - 2];
            }
            catch (Exception)
            {
                return null;
            }
        }

        private IEnumerable<TestCaseData> GetEcqFields()
        {
            TestBaseInit();
            yield return new TestCaseData(_getEcqById(1062).ECQ)
                .Returns("case");
            yield return new TestCaseData(_getEcqById(1059).ECQ).Returns("bi.PERIOD_ID");
            yield return new TestCaseData(_getEcqById(1061).ECQ).Returns("t.SUMMA");
        }

        private IEnumerable<TestCaseData> GetEcqFieldsRandomIndexes()
        {
            TestBaseInit();
            yield return new TestCaseData(_getEcqById(1062).ECQ).Returns("лиц.счет");
            yield return new TestCaseData(_getEcqById(1059).ECQ).Returns("расч.период");
            yield return new TestCaseData(_getEcqById(1061).ECQ).Returns("л/с");
        }

        private IEnumerable<TestCaseData> GetEcqFieldsLatestIndexes()
        {
            TestBaseInit();
            yield return new TestCaseData(_getEcqById(1062).ECQ).Returns(";");
            yield return new TestCaseData(_getEcqById(1059).ECQ).Returns("KeyField");
            yield return new TestCaseData(_getEcqById(1061).ECQ).Returns("KeyField");
        }

    }
}
